/*

Author   : chaos

FileName : composition.cpp

Date     : 15/08/17 03:30:16

*/
#include <iostream>
#include <cstring>
using namespace std;

class person
{
    protected:
        char last_name[5];
        char first_name[15];

    public:
        person(const char * l_name,const char * f_name)
        {
            strcpy(last_name,l_name);
            strcpy(first_name,f_name);
        }
        person(){}

        void show_data()
        {cout << first_name << " " << last_name;}
};

class father:public virtual person
{
    public:
        father(const char * last_name, const char * first_name)
            :person(last_name,first_name){}
        father(){}
        char * get_last_name(){return last_name;}
};

class mother:public virtual person
{
    public:
        mother(const char * last_name, const char * first_name)
            :person(last_name,first_name){}
        mother(){}
};

class child:public father,public mother
{
    private:
        father & my_father;
        mother & my_mother;
    public:
        child(father &,mother &, const char *);
        void show_data();
};

child::child(father & a_father,mother & a_mother,const char * name)
    :my_father(a_father),my_mother(a_mother)
{
    strcpy(last_name,a_father.get_last_name());
    strcpy(first_name,name);
}

void child::show_data()
{
    person::show_data();
}

class family
{
    private:
        father & a_father;
        mother & a_mother;
        child ** child_list;
        int child_num;

    public:
        family(father & a_father, mother & a_mother,child ** a_child_list,int num)
            :a_father(a_father),a_mother(a_mother),child_num(num)
        {
            child_list = new child * [child_num];

            for(int i = 0; i < child_num ; i++)
                child_list[i] = *(a_child_list + i);
        }

        void show_family_mem()
        {
            cout << "Father is ";
            a_father.show_data();
            cout << "." << endl <<"Mother is";
            a_mother.show_data();
            cout <<"." << endl << "There are " << child_num
                << "children." << endl << "They are ..." << endl;

            for(int i = 0; i < child_num; i++)
            {
                child_list[i]->show_data();
                cout << endl;
            }
        }
};
int main(int argc ,char *argv[])
{
    father a_father("Kuo","John");
    mother a_mother("Lin","Mary");

    child * children[2];

    children[0] = new child(a_father,a_mother,"Joe");
    children[1] = new child(a_father,a_mother,"Mary");

    family a_family(a_father,a_mother,children,2);

    a_family.show_family_mem();
    return 0;
}
